<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');


class Admin extends CI_Controller
{
	public function __construct()
	{
		parent::__construct();
		$this->load->model('admin_model');
	}
	
	public function index()
	{
		$data['css'][0] = "<link type='text/css' rel='stylesheet' href='".base_url()."css/login.css'>";
		$data['css'][1] = "<link type='text/css' rel='stylesheet' href='".base_url()."css/jq_login.css'>";
		$data['title'] = '健康之友';
		$this->load->view("_header", $data);
		$this->load->view("admin/main/main");
		$this->load->view("_footer");
	}
	
	public function logout_admin()
	{
		$this->session->sess_destroy();
		redirect("login");
	}
	
	public function left()
	{
		$this->load->view("admin/main/left");
	}
	
	public function right()
	{
		utf8_echo("欢迎来到管理页面");
	}
	
	public function user_manage()
	{
		$all_user_info = $this->admin_model->get_all_user_info();
		$data = array ("all_user_info"=>$all_user_info);
		$this->load->view("admin/user/userManage", $data);
	}
	
	public function health_info_manage()
	{
		$health_info = $this->admin_model->get_health_info();
		$data = array(
				"health_info" => $health_info
				);
		$this->load->view("admin/healthInfo/healthInfoManage", $data);
	}
	
	public function add_field()
	{
		$field = $this->input->post("field");
		$desc = $this->input->post("desc");
		$type_code = $this->input->post("type");
		
		$this->admin_model->add_health_info($field, $type_code, $desc);
		jump_to_last_page();
	}
	
	public function remove_field($field)
	{
		$this->admin_model->remove_health_info($field);
		jump_to_last_page();
	}
	
	public function test_data_generation()
	{
		$this->load->view("admin/dataGen/testDataGen");
	}
	
	public function gen_test_data()
	{
		$num = $this->input->post("num");
		$prefix = $this->input->post("prefix");
		$this->admin_model->gen_test_data($num, $prefix);
		utf8_echo("生成成功");
	}
	
	public function remove_user($uid)
	{
		$this->admin_model->remove_user($uid);
		jump_to_last_page();
	}
	
	public function remove_all_user()
	{
		
		$this->admin_model->remove_all_user();
		jump_to_last_page();
	}
}
?>